package com.baidu.controller;


import com.baidu.pojo.TbCategory;
import com.baidu.service.TbCategoryService;
import com.baidu.utils.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 分类管理控制层
 *
 * 宋金航
 */
@RestController
@RequestMapping("category")
@Api(tags = "category",produces = "test")
@CrossOrigin
public class CategoryController {

    @Autowired
    private TbCategoryService tbCategoryService;

    /**
     * 查询所有顶级数据
     * @param parentId 为0的是顶级数据
     * @return
     */
    @ApiImplicitParam(name = "id",value = "id",paramType = "query",required = false)
    @GetMapping("findCategorys")
    public ResultResponse findCategorys(Long parentId){
        return this.tbCategoryService.findCategorys(parentId);
    }

    /**
     * 修改和添加
     * @param tbCategory
     * @return
     */
    @PostMapping("saveAndUpdate")
    public ResultResponse insert(@RequestBody TbCategory tbCategory){
        return this.tbCategoryService.saveAndUpdate(tbCategory);
    }

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @GetMapping("findById/{id}")
    public ResultResponse findById(@PathVariable("id")Long id){
        return this.tbCategoryService.findById(id);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("deleteIds/{ids}")
    public ResultResponse deleteIds(@PathVariable("ids")Long[] ids){
        return this.tbCategoryService.deleteIds(ids);
    }

}
